# @Time : 2020/7/30 15:27
# @Author : Fioman 
# @Phone : 13149920693
import cv2 as cv
import numpy as np

"""
retval,triangle = cv.minEnclosingTriangle(points)
retval,最小外包三角形面积.
triangle,最小外包三角形的三个顶点集
"""
img = cv.imread("cc.bmp")
gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)

cv.imshow("Original", img)
T, thres = cv.threshold(gray, 127, 255, cv.THRESH_BINARY)
image, contours, hierarchy = cv.findContours(thres, cv.RETR_LIST, cv.CHAIN_APPROX_SIMPLE)

area, triangle = cv.minEnclosingTriangle(contours[0])
print("area = {}".format(area))
print("triangle = {}".format(triangle))

for i in range(0, 3):
    cv.line(img, tuple(triangle[i][0]), tuple(triangle[(i + 1) % 3][0]), (0, 255, 0), 1)

cv.imshow("minTriangle",img)
cv.waitKey(0)
cv.destroyAllWindows()